//var ROOTBASE="http://localhost:8080/";
 var ROOTBASE="http://114.55.61.211:80/";
var DOMAIN = "http://o71tin5mf.bkt.clouddn.com/";
function TIMEConverter(UNIX_timestamp){
  var a = new Date(UNIX_timestamp);
  // var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  var year = twoDigits(a.getFullYear());
  var month = twoDigits(a.getMonth()+1);
  var date = twoDigits(a.getDate());
  var hour = twoDigits(a.getHours());
  var min = twoDigits(a.getMinutes());
  var sec = twoDigits(a.getSeconds());
  var time = year+"-"+month+"-"+date+" "+hour+":"+min+":"+sec;
  return time;
}
function twoDigits(value) {
   if(value < 10) {
    return '0' + value;
   }
   return value;
}
// 格式化日期格式
// 3月6日 周日 9:00
function FORMATTIME(UNIX_timestamp){
  var a = new Date(UNIX_timestamp);
  var dayNames = new Array("周日","周一","周二","周三","周四","周五","周六");
  var month = a.getMonth()+1;
  var day = a.getDate();
  var weekname = dayNames[a.getDay()];
  var hour = a.getHours();
  var min = a.getMinutes();
  var time = month+"月"+day+"日 "+weekname+" "+hour+":"+min;
  return time;
}
  function user() {
    $.ajax({
      url: ROOTBASE + "user/islogin",
      type: "GET",
      async: false,
      success: function (data, status, xhr) {
        console.log(data);
        if(data.sucflag){
          $(".fright #login").css("display","none");
          $(".fright #register").css("display","none");
          $(".top_left").css("display","block");
          $("#head").css("display","block");
          $(".top_left span").html("欢迎你,"+data.userT.username);
          $("#head span").html("<a href='javascript:background();' style='cursor: hand;color: red'>"+data.userT.username+"</a>,");
          $("#loginout").show();
          $(".user #username #pname").html(data.userT.username);
          $(".user #username #integral").html("积分:"+data.userT.point+"分");
          $("#register").css("display","none");
          $("#login").css("display","none");
          if(data.userT.nickname==null ||data.userT.nickname=="" ){
            //$(".user #username h2").html(my);
            $(".user #username h2").html("");
          }else {
            $(".user #username h2").html(data.userT.nickname);
          }
          if(data.userT.portrait==null || data.userT.portrait==""){
            $(".user h1 img").attr("src","../images/user.gif");
          }else {
            $(".user h1 img").attr("src",data.userT.portrait);
          }
        }
      }
      //,error:function(data,status,xhr){
      //  $(".fright #login").css("display","block");
      //  $(".fright #register").css("display","block");
      //  $(".top_left").css("display","none");
      //  $("#head").css("display","none");
      //  $(".top_left").css("display","none");
      //}
    });
  }

function background(){
  window.location.href="/user/UserCenter.html";
}

function orguser() {
  $.ajax({
    url: ROOTBASE + "user/islogin",
    type: "GET",
    async: false,
    success: function (data, status, xhr) {
     if(data.sucflag) {
       $(".top_left span").html("欢迎你,"+data.userT.username);
     }else {
       $(".top_left").html("<a href='../orglogin.html' >登录</a>")
     }

    }
    //,error:function(data,status,xhr){
    //  location.href=ROOTBASE+"login.html";
    //}


  });
}
function loginOut() {
  $.ajax({
    url: ROOTBASE + "user/logout",
    type: "POST",
    async: false,
    success: function (data, status, xhr) {
      location.href=ROOTBASE+"login.html";
    },error:function(data, status, xhr){
      location.href=ROOTBASE+"login.html";
    }
  });
}
function OrgloginOut() {
  $.ajax({
    url: ROOTBASE + "user/logout",
    type: "POST",
    async: false,
    success: function (data, status, xhr) {
      parent.location.href = ROOTBASE + "orglogin.html";
    }, error: function (data, status, xhr) {
      parent.location.href = ROOTBASE + "orglogin.html";
    }
  });
}

function userdetail() {
  $.ajax({
    url: ROOTBASE + "user/islogin",
    type: "GET",
    async: false,
    success: function (data, status, xhr) {
      if(data.sucflag) {
        $("#username").html(data.userT.username);
      }
    }
  });
}



//机构中心用户权限
var userRole=function() {
  $.ajax({
    url: ROOTBASE + "userorganization/userRole",
    type: "GET",
    success: function (data, status, xhr) {
      if (data.sucflag) {
        var orgmodule = data.organizationModuleTs;

        var rolEHTML = "<li><a href='../organization/InstitutUserC.html' target='right'>机构主页</a></li>" +
            "<li class='current'><a href='../organization/InstitutMessage.html' target='right'>机构信息</a></li>";

        for (var i = 0; i < orgmodule.length; i++) {
          if (orgmodule[i].modoulename == "场地管理") {
            rolEHTML += "<li><a href='../organization/SiteManage.html' target='right'>场地管理</a></li>";
          }
          if (orgmodule[i].modoulename == "活动管理") {
            rolEHTML += "<li><a href='../organization/ActivityManage.html' target='right'>活动管理</a></li>";
          }
          if (orgmodule[i].modoulename == "成员管理") {
            rolEHTML += "<li><a href='../organization/MemberManage.html' target='right'>成员管理</a></li>";
          }
          if (orgmodule[i].modoulename == "场地出租") {
            rolEHTML += "<li><a href='../organization/VenueRental.html' target='right'>场地出租</a></li>";
          }
          if (orgmodule[i].modoulename == "用户管理") {
            rolEHTML += "<li><a href='../user/UserManage.html' target='right'>用户管理</a></li>";
          }
          if (orgmodule[i].modoulename == "通知消息") {
            rolEHTML += "<li><a href='../organization/NotificatMessage.html' target='right'>通知消息</a></li>";
          }
          if (orgmodule[i].modoulename == "统计管理") {
            rolEHTML += "<li><a href='../organization/StateMessage.html' target='right'>统计管理</a></li>";
          }
          if (orgmodule[i].modoulename == "权限管理") {
            rolEHTML += "<li><a href='../organization/AuthorityMessage.html' target='right'>权限管理</a></li>";
          }
          if (orgmodule[i].modoulename == "公告管理") {
            rolEHTML += "<li><a href='../organization/Announcements.html' target='right'>公告管理</a></li>";
          }
          if (orgmodule[i].modoulename == "文化资源") {
            rolEHTML += "<li><a href='../organization/CulturalResources.html' target='right'>文化资源</a></li>";
          }
          if (orgmodule[i].modoulename == "审核管理") {
            rolEHTML += "<li><a href='../organization/AuditManage.html' target='right'>审核管理</a></li>";
          }
        }
      }else {
        rolEHTML="<li><a href='../organization/InstitutUserC.html' target='right'>机构主页</a></li>" +
                "<li class='current'><a href='../organization/InstitutMessage.html' target='right'>机构信息</a></li>"+
            "<li><a href='../organization/SiteManage.html' target='right'>场地管理</a></li>"+
            "<li><a href='../organization/ActivityManage.html' target='right'>活动管理</a></li>"+
            "<li><a href='../organization/MemberManage.html' target='right'>成员管理</a></li>"+
            "<li><a href='../organization/VenueRental.html' target='right'>场地出租</a></li>"+
            "<li><a href='../user/UserManage.html' target='right'>用户管理</a></li>"+
            "<li><a href='../organization/NotificatMessage.html' target='right'>通知消息</a></li>"+
            "<li><a href='../organization/StateMessage.html' target='right'>统计管理</a></li>"+
            "<li><a href='../organization/AuthorityMessage.html' target='right'>权限管理</a></li>"+
            "<li><a href='../organization/Announcements.html' target='right'>公告管理</a></li>"+
            "<li><a href='../organization/CulturalResources.html' target='right'>文化资源</a></li>"+
            "<li><a href='../organization/AuditManage.html' target='right'>审核管理</a></li>";
      }
      $("#leftNav ul").html(rolEHTML);

    }
  });
}

//机构中心用户权限
var userRoleAction=function() {
  $.ajax({
    url: ROOTBASE + "userorganization/userRole",
    type: "GET",
    success: function (data, status, xhr) {
      if (data.sucflag) {
        var recordnumber=0
        $(".bm_swtich_all li").css("display","none");
        $(".all_bm_cont").css("display","none");
        var orgmodule = data.organizationModuleActionTs;
        //for(var i=0;i<orgmodule.length();i++){
          $(".bm_swtich_all li").each(function (k,v) {
            var li=$(this)
              var tli=$(this).html();
            for(var i=0;i<orgmodule.length;i++){
              if(tli==orgmodule[i].moduleactionname){
                if(recordnumber==0){
                  $(".all_bm_cont").each(function (n,e) {
                    if(k==n){
                      $(this).show();
                    }
                  })
                }
                recordnumber++;
                li.show();
              }
            }
          })
       // }
      }
    }
  });
}
/***
 * 跳转至活动页
 * @param e
 */
goSearch=function(e){
    location.href=ROOTBASE+"FrontPage/list.html?search="+e;
}
var hotkey=function(){
  var html = "";
  $.ajax({
      url:ROOTBASE+'search/hotkey?size=8',
      type:'GET',
      success:function(data,status,xhr){
          console.log(data);
          for(var i=0;i<data.content.length;i++){
              var hot = data.content[i]
              html += "<li><a href='javascript:void(0)' onClick='goSearch(\""+hot.key+"\")'>"+hot.key+"</a></li>";
          }
          $("#hotkey").html(html);
      }
  });
}
